<?PHP
require_once('config.inc.php');
require_once('database.inc.php');
require_once('functions.inc.php');
require_once(LIBRARY_PATH.'json/JSON.php');
require('security.php');

$db = LinkDB();
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);

$id = @$_GET['id'];
$basic = $db->GetRow('SELECT * FROM people WHERE id = ?', $id);
$orderString = ' ORDER BY name';
if (!$basic) feedback(false, '[找不到指定的联系人信息]');
$contact = $db->GetAll('SELECT * FROM contactinfo WHERE fatherid = ?'.$orderString, $id);
$contactItems = array();
if ($contact) {
	foreach ($contact as $item) {
		$contactItems[] = array('title'  => $item['name'], 'content'=> $item['content']);
	}
}
$result = array(
    'isSucceed'=> true,
    'data'     => array(
	    'basicInfo'  => array(
	        'styleClass'=> 'basicInfo',
	        'title'     => '基础信息',
	        'items'     => array(
	             array('title'  => '姓名', 'content'=> $basic['name']),
	             array('title'  => '生日', 'content'=> $basic['birthday']),
	             array('title'  => '性别', 'content'=> $basic['sex'])
	        )
	    ),
	    'contactInfo'=> array(
	        'styleClass'=> 'contactInfo',
	        'title'     => '联系方式',
	        'items'     => $contactItems
	    ),
	    'remark'     => array(
	        'styleClass'=> 'remark',
	        'title'     => '备注',
	        'items'     => array(
	            array('content'=> $basic['remark'])
	        )
	    )
    )
);
echo $json->encode($result);
/**
 * 数据模板
{
	'isSucceed' : true,
	'basicInfo'	: {
		'styleClass' : 'basicInfo',
		'title'      : '基础信息',
		'items'      : [
			{'title':'姓名','content':'潘莹'},
			{'title':'生日','content':'1982.02.19'}
		]
	},

	'contactInfo'	: {
		'styleClass' : 'contactInfo',
		'title'      : '联系方式',
		'items'      : [
			{'title':'手机','content':'13644882468'},
			{'title':'办公电话','content':'64426699-285'}
		]
	},

	'remark'	: {
		'styleClass' : 'remark',
		'title'	     : '备注',
		'items'	     : [
			{'content':'张三是个好同志张三是个好同志张三是'}
		]
	}
}
 */
?>